export const state = () => ({
  menus:[
    {
      icon:"home",
      title:"首页",
      src:"/",
      children:[]
    },
    {
      icon:"user",
      title:"用户管理",
      src:"/user",
      children:[]
    },
    {
      icon:"file",
      title:"文件管理",
      src:"",
      children:[
        {
          title:"小说管理",
          src:"/file"
        },
        // {
        //   title:"用户文件管理",
        //   src:"/file/userFile"
        // }
      ]
    },
    // {
    //   icon:"web",
    //   title:"网站管理",
    //   src:"",
    //   children:[
    //     {
    //       title:"反馈管理",
    //       src:"/web/feedback"
    //     },
    //     {
    //       title:"评论管理",
    //       src:"/web/comment"
    //     }
    //   ]
    // }
  ],
  routes:[]
})
export const mutations = {
  setRoute(state,routes){
    state.routes = routes
  },
  addRoute(state,route){
    let isRep = false
    if(state.routes.length > 0){
      state.routes.map((item,index) => {
        if(item.name === route.name && item.params === route.params){
          //从当前位置移除route
          // state.routes.splice(index,1)
          isRep = true
        }
      })
    }
    if(!isRep){
      state.routes.push(route)
    }
  },
  closeRoute(state,route){
    state.routes.map((item,index) => {
      if(item.name === route.name && item.params === route.params){
        state.routes.splice(index,1)
      }
    })
  },
  /**
   * 清空route tag
   * @param state
   */
  clearRoute(state){
    state.routes = []
    window.localStorage.removeItem('routeTag')
  },
  updateLocaRoute(state){
    console.log("setroute")
    window.localStorage.setItem('routeTag',JSON.stringify(state.routes))
  },
}
export const actions = {
  closeRoute(state,route){
    state.commit('closeRoute',route)
    state.commit('updateLocaRoute')
  },
  addRoute(state,route){
    state.commit('addRoute',route)
    state.commit('updateLocaRoute')
  }
}
export default {
  namespace:true,
  state,
  mutations,
  actions
}
